Open
Conversation
| # data file | ||
| alpaca_data/ | ||
| libai/version.py | ||
| sft_result |
| example = tokenizer.tokenize( | ||
| full_prompt_and_response, add_bos=True, add_eos=True, device="cpu" | ||
| full_prompt_and_response, add_bos=True, add_eos=True, device=None, | ||
| # device="cpu" |
xiezipeng-ML
reviewed
Nov 2, 2024
|
|
||
| self.scale_mask_softmax_fusion = scale_mask_softmax_fusion | ||
|
|
||
| self.query_key_value = Linear( |
Contributor
There was a problem hiding this comment.
这个实现有问题导致的之后的k,v相关计算对不上,GQA里k,v的num_head数量和q不一样,参考chatglm的方式实现:
libai/projects/ChatGLM/chatglm.py
Lines 245 to 259 in 9dcbe3b
xiezipeng-ML
reviewed
Nov 2, 2024
| query_key_value = query_key_value.permute( | ||
| 0, 2, 1, 3 | ||
| ) # [bsz, num_heads, src_len, 3 * head_size] | ||
| query, key, value = flow.chunk(query_key_value, chunks=3, dim=-1) |
Contributor
There was a problem hiding this comment.
这里的k和v的num_head排列顺序有问题,GQA里是多个q_head对应单个k_head,v_head,
举个例子
# k的h1对应q的h1,h2
q: [h1, h2, h3, h4]
k: [ h1, h2]
v: [ h1, h2]
repeat k,v的head后:
# k的h1对应q的h1,h2
q: [h1, h2, h3, h4]
k: [h1, h1, h2, h2]
v: [h1, h1, h2, h2]
但是这里的实现结果k,v head排列顺序有问题,所以之后计算是有问题的
# k的h1对应q的h1,h2
q: [h1, h2, h3, h4]
k: [h1, h2, h1, h2]
v: [h1, h2, h1, h2]
参考chaglm的实现:
libai/projects/ChatGLM/chatglm.py
Lines 332 to 356 in 9dcbe3b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.